package cn.icare.cms.controller;

import cn.icare.cms.*;
import cn.icare.cms.config.WxInfoConfig;
import cn.icare.cms.dao.po.Member;
import cn.icare.cms.dao.po.MemberAddress;
import cn.icare.cms.dao.po.Order;
import cn.icare.cms.model.enums.OrderStatusEnum;
import cn.icare.cms.model.ro.*;
import cn.icare.cms.model.vo.rest.MsgDatasVO;
import cn.icare.cms.model.vo.rest.RespMsgVO;
import cn.icare.cms.model.wx.ro.WxConfig;
import cn.icare.cms.model.wx.ro.WxPayInfoRo;
import cn.icare.cms.model.wx.vo.WxPayInfoVo;
import cn.icare.cms.sync.SyncOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.*;

/**
 * @Classname ItemOrderController
 * @Description TODO
 * @Date 2020/3/16 16:59
 * @Created by Administrator
 */
@CrossOrigin
@RestController
@RequestMapping(value = "/rest/personal/master")
@Api(tags = "REST团长功能接口")
public class AreaMasterController extends BaseController {





    @Autowired
    private OrderService orderService;

    private final Logger logger = LoggerFactory.getLogger(AreaMasterController.class);



    @GetMapping()
    @ApiOperation(value = "查询会员订单列表", notes = "查询会员订单列表")
    @ApiImplicitParams({

            @ApiImplicitParam(name = "beginTime", value = "开始时间", required = false, paramType = "query", dataTypeClass = String.class),
            @ApiImplicitParam(name = "endTime", value = "结束时间", required = false, paramType = "query", dataTypeClass = String.class),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, defaultValue = "1", paramType = "query", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = true, defaultValue = "20", paramType = "query", dataTypeClass = Integer.class)
    })
    public ResponseEntity<RespMsgVO> getList(
                                             String beginTime,
                                             String endTime,
                                             Integer pageNum,
                                             Integer pageSize
            ,HttpServletRequest request) {
        Long memberId = this.getCurrentUserId(request);
        //Long memberId=26L; //TODO 测试
        if (memberId <= 0) {
            return super.getRespFail("会员身份验证信息不正确");
        }
        Map map=orderService.getMasterOrderList(memberId,beginTime,endTime,pageNum,pageSize);
        return super.getRespOk(map);
    }

    @GetMapping("/daytotalinfo")
    @ApiOperation(value = "查询当天订单统计信息", notes = "查询当天订单统计信息")
    public ResponseEntity<RespMsgVO> getDayTotalInfo(HttpServletRequest request) {
        Long memberId = this.getCurrentUserId(request);
        //Long memberId=26L; //TODO 测试
        if (memberId <= 0) {
            return super.getRespFail("会员身份验证信息不正确");
        }
        String beginTime=DateUtil.formateToDateTime(new Date(),"yyyy-MM-dd 00:00:00");
        String endTime=DateUtil.formateToDateTime(new Date(),"yyyy-MM-dd 23:59:59");
        Map map=orderService.getMasterOrderTotal(memberId,beginTime,endTime);
        return super.getRespOk(map);
    }



}
